package com.zengqingfa.springboot.redis.rest;

import com.zengqingfa.springboot.redis.helper.RedisIdentityHelper;
import com.zengqingfa.springboot.redis.sequence.CommonLocalCacheService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zengqingfa
 * @className RedisSequenceController
 * @description
 * @create 2023/1/4 21:26
 */
@RestController
@RequestMapping("/redisSequence")
public class RedisSequenceController {


    @Resource
    private CommonLocalCacheService commonLocalCacheService;

    /**
     * 测试redis生成编码
     *
     * @param prefix 前缀
     * @return
     */
    @GetMapping("/generatorId")
    public String generatorId(@RequestParam("prefix") String prefix) {
        String s = commonLocalCacheService.generatorId(prefix, 3);
        return s;
    }

    /**
     * 测试redis生成编码不带随机数
     *
     * @param prefix 前缀
     * @return
     */
    @GetMapping("/defaultGeneratorId")
    public String defaultGeneratorId(@RequestParam("prefix") String prefix) {
        String s = commonLocalCacheService.defaultGeneratorId(prefix);
        return s;
    }


    /**
     * 测试redis生成编码不带随机数不带前缀
     *
     * @return
     */
    @GetMapping("/generatorIdWithoutPrefix")
    public String generatorIdWithoutPrefix() {
        String s = commonLocalCacheService.generatorIdWithoutPrefix();
        return s;
    }


    @Resource
    private RedisIdentityHelper redisIdentityHelper;

    /**
     * 测试redis生成编码
     *
     * @param prefix 前缀
     * @return
     */
    @GetMapping("/getCommonCode")
    public String getCommonCode(@RequestParam("prefix") String prefix) {
        String s = redisIdentityHelper.getCommonCode(prefix);
        return s;
    }
}